import '../index.dart';

class DarkModePage extends StatelessWidget {
  const DarkModePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var color = Theme.of(context).primaryColor;
    var darkModel = Provider.of<DarkModel>(context);
    var s = S.of(context);
    Widget _buildFontSizeItem(String lan, value) {
      return ListTile(
        title: Text(
          lan,
          // 对APP当前语言进行高亮显示
          style: TextStyle(color: darkModel.darkMode == value ? color : null),
        ),
        trailing:
            darkModel.darkMode == value ? Icon(Icons.done, color: color) : null,
        onTap: () {
          // 此行代码会通知MaterialApp重新build
          darkModel.darkMode = value;
        },
      );
    }

    return GlobalStyle(
      child: BackgroundStyleWidget(
        child: Scaffold(
          appBar: AppBar(
            title: Text(
              s.darkMode,
            ),
            centerTitle: true,
          ),
          body: ListView(
            children: <Widget>[
              _buildFontSizeItem(s.settingsSystemDefault,
                  DarkModelOption.darkModelOptionSystem.index),
              _buildFontSizeItem(
                  s.dark, DarkModelOption.darkModelOptionDark.index),
              _buildFontSizeItem(
                  s.light, DarkModelOption.darkModelOptionLight.index),
            ],
          ),
        ),
      ),
    );
  }
}
